package cn.edu.gdpt.mobile213.mobile2121606097wjc0331;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class MainActivity extends AppCompatActivity {
    private RadioGroup radgupmaincartype;
    private RadioButton radbtnmainsaloon;
    private RadioButton radbtnmainmpv;
    private RadioButton radbtnmainsuv;
    private RadioGroup radgupmainrooms;
    private RadioButton radbtnmainroom1;
    private RadioButton radbtnmainroom2;
    private RadioButton radbtnmainroom3;
    private RadioButton radbtnmainroom4;
    private Button btnmaincreateline;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initview();
        radgupmaincartype.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton=findViewById(i);
                Log.i("radgupmaincartype",radioButton.getText().toString());
            }
        });
        radgupmainrooms.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton=findViewById(i);
                Log.i("radgupmainrooms",radioButton.getText().toString());
            }
        });
        btnmaincreateline.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String msg="";
                int cartypeid=radgupmaincartype.getCheckedRadioButtonId();
                if (cartypeid!=-1){
                    msg=((RadioButton)findViewById(cartypeid)).getText().toString();
                }else {
                    msg="未选车型";
                }
                int roomid=radgupmainrooms.getCheckedRadioButtonId();
                if (roomid!=-1){
                    msg+=","+((RadioButton)findViewById(roomid)).getText().toString();
                }else{
                    msg+=",未选生产车间";
                }
                Log.i("Button",msg);
            }
        });
    }

    private void initview() {
        radgupmaincartype=(RadioGroup) findViewById(R.id.radgupmaincartype);
        radbtnmainsaloon=(RadioButton) findViewById(R.id.radbtnmainsaloon);
        radbtnmainmpv=(RadioButton) findViewById(R.id.radbtnmainmpv);
        radbtnmainsuv=(RadioButton) findViewById(R.id.radbtnmainsuv);
        radgupmainrooms=(RadioGroup) findViewById(R.id.radgupmainrooms);
        radbtnmainroom1=(RadioButton) findViewById(R.id.radbtnmainroom1);
        radbtnmainroom2=(RadioButton) findViewById(R.id.radbtnmainroom2);
        radbtnmainroom3=(RadioButton) findViewById(R.id.radbtnmainroom3);
        radbtnmainroom4=(RadioButton) findViewById(R.id.radbtnmainroom4);
        btnmaincreateline=(Button) findViewById(R.id.btnmaincreateline);
    }
}